package com.map.pruebaMapa;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import android.os.Bundle;
import android.widget.TextView;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;

public class HelloGoogleMaps extends MapActivity implements LocationListener{
	public Location loc=null;
	
	public Address objetoDireccion;
	public List<Address> direccion;
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.main);
	    // busca el componente mapview para funcionar
        MapView mapView = (MapView) findViewById(R.id.mapview);
        TextView lblhello = (TextView) findViewById(R.id.lbl_text);
        
        // setBuiltInZoomControls habilita la lupa
        
        mapView.setBuiltInZoomControls(true);
        
        Geocoder geo= new Geocoder(this);
		try {
			direccion = geo.getFromLocationName("Buenos Aires, Argentina", 4);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
		}
		
		
        Iterator<Address> it=direccion.iterator();
        
        if(it.hasNext())
        {
        	objetoDireccion=(Address) it.next();
        	
        }
  
        // */
        
        int latitude = (int)(objetoDireccion.getLatitude() * 1000000); 
        int longitude = (int)(objetoDireccion.getLongitude() * 1000000); 
        //int latitude = (int)(34 * 1000000); 
        //int longitude = (int)(1.3 * 1000000); 
        
        GeoPoint point = new GeoPoint(latitude,longitude);
        mapView.getController().setZoom(10);
        mapView.getController().setCenter(point);      
         
	}

	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}

	public void onLocationChanged(Location arg0) {
		// TODO Auto-generated method stub
		
	}

	public void onProviderDisabled(String arg0) {
		// TODO Auto-generated method stub
		
	}

	public void onProviderEnabled(String arg0) {
		// TODO Auto-generated method stub
		
	}

	public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
		// TODO Auto-generated method stub
		
	}

}
